using System;

using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;

namespace Microsoft.NETMF.BikeComputer.Application
{
    public class SummaryView : View
    {


        public SummaryView(RideDataModel model)
            : base(model)
        {

            StackPanel summaryPanel = new StackPanel(Orientation.Vertical);
            summaryPanel.HorizontalAlignment = HorizontalAlignment.Center;
            summaryPanel.VerticalAlignment = VerticalAlignment.Center;

            ////////////////////////////////////////////////////////////////////////////////////////
            //  Top Area
            //

            StackPanel  _topPanel = new StackPanel(Orientation.Horizontal);
            _topPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _topPanel.VerticalAlignment = VerticalAlignment.Center;

            Text _date = new Text(Resources.GetFont(Resources.FontResources.small), DateTime.Today.Month.ToString() +"/" + DateTime.Today.Day.ToString() + "/" + DateTime.Today.Year.ToString());
            _date.SetMargin(0, 0,40, 0);

            Text _time = new Text(Resources.GetFont(Resources.FontResources.small), DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString());
            _time.SetMargin(0, 0, 40, 0);

            Text _temperature = new Text(Resources.GetFont(Resources.FontResources.small), "72" + " degrees");  //placeholder until we get the sensor hooked up

            _topPanel.Children.Add(_date);
            _topPanel.Children.Add(_time);
            _topPanel.Children.Add(_temperature);



            ////////////////////////////////////////////////////////////////////////////////////////
            //  Middle Area
            //
            StackPanel _midPanel = new StackPanel(Orientation.Horizontal);
            _midPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _midPanel.VerticalAlignment = VerticalAlignment.Center;
   
            StackPanel _leftMidPanel = new StackPanel(Orientation.Vertical);
            _leftMidPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _leftMidPanel.VerticalAlignment = VerticalAlignment.Top;
            _leftMidPanel.SetMargin(0,0,0,40);

            Text _totalTime = new Text(Resources.GetFont(Resources.FontResources.nina48), "8:09");
            _totalTime.HorizontalAlignment = HorizontalAlignment.Center;
            Text _totTimeLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.TotalTimeText));
            _totTimeLabel.HorizontalAlignment = HorizontalAlignment.Center;


            _leftMidPanel.Children.Add(_totalTime);
            _leftMidPanel.Children.Add(_totTimeLabel);

            StackPanel _midMidPanel = new StackPanel(Orientation.Vertical);
            _midMidPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _midMidPanel.SetMargin(30, 40, 30, 0);

            Text _aveSpeed = new Text(Resources.GetFont(Resources.FontResources.nina48), "18.4");
            _aveSpeed.VerticalAlignment = VerticalAlignment.Bottom;
            _aveSpeed.HorizontalAlignment = HorizontalAlignment.Center;
            Text _aveMphLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.AveSpeedText));
            _aveMphLabel.VerticalAlignment = VerticalAlignment.Bottom;
            _aveMphLabel.HorizontalAlignment = HorizontalAlignment.Center;

            _midMidPanel.Children.Add(_aveSpeed);
            _midMidPanel.Children.Add(_aveMphLabel);

            StackPanel _rightMidPanel = new StackPanel(Orientation.Vertical);
            _rightMidPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _rightMidPanel.SetMargin(0, 0, 0, 40);

            Text _aveCadence = new Text(Resources.GetFont(Resources.FontResources.nina48), "72");
            _aveCadence.HorizontalAlignment = HorizontalAlignment.Center;

            Text _aveRpmLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.AveCadenceText));
            _aveRpmLabel.HorizontalAlignment = HorizontalAlignment.Center;

            _rightMidPanel.Children.Add(_aveCadence);
            _rightMidPanel.Children.Add(_aveRpmLabel);


            _midPanel.Children.Add(_leftMidPanel);
            _midPanel.Children.Add(_midMidPanel);
            _midPanel.Children.Add(_rightMidPanel);


            ////////////////////////////////////////////////////////////////////////////////////////
            //  Bottom Area
            //
            StackPanel _bottomPanel = new StackPanel(Orientation.Horizontal);
            _bottomPanel.HorizontalAlignment = HorizontalAlignment.Center;

            StackPanel _leftBottomPanel = new StackPanel(Orientation.Vertical);

            Text _aveClimbRate = new Text(Resources.GetFont(Resources.FontResources.nina48), "87");
            _aveClimbRate.HorizontalAlignment = HorizontalAlignment.Center;

            Text _aveFtmLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.AveClimbText));
            _aveFtmLabel.HorizontalAlignment = HorizontalAlignment.Center;

            _leftBottomPanel.Children.Add(_aveClimbRate);
            _leftBottomPanel.Children.Add(_aveFtmLabel);

            StackPanel _midBottomPanel = new StackPanel(Orientation.Vertical);

            Text _elevChange = new Text(Resources.GetFont(Resources.FontResources.nina48), "+247");
            _elevChange.HorizontalAlignment = HorizontalAlignment.Center;

            Text _elevChgLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.TotalElevText));
            _aveFtmLabel.HorizontalAlignment = HorizontalAlignment.Center;

            _midBottomPanel.Children.Add(_elevChange);
            _midBottomPanel.Children.Add(_elevChgLabel);
            _midBottomPanel.SetMargin(20, 0, 20, 0);

            StackPanel _rightBottomPanel = new StackPanel(Orientation.Vertical);

            Text _totalDistance = new Text(Resources.GetFont(Resources.FontResources.nina48), "56.9");
            _totalDistance.HorizontalAlignment = HorizontalAlignment.Center;

            Text _TotalMilesLabel = new Text(Resources.GetFont(Resources.FontResources.small), Resources.GetString(Resources.StringResources.TotalDistanceText));
            _TotalMilesLabel.HorizontalAlignment = HorizontalAlignment.Center;

            _rightBottomPanel.Children.Add(_totalDistance);
            _rightBottomPanel.Children.Add(_TotalMilesLabel);

            _bottomPanel.Children.Add(_leftBottomPanel);
            _bottomPanel.Children.Add(_midBottomPanel);
            _bottomPanel.Children.Add(_rightBottomPanel);


            _pausedPanel = new StackPanel(Orientation.Vertical);
            _pausedPanel.Visibility = Visibility.Hidden;

            Text _pausedText = new Text(Resources.GetFont(Resources.FontResources.nina14), Resources.GetString(Resources.StringResources.PausedText));
            _pausedText.HorizontalAlignment = HorizontalAlignment.Center;
            _pausedPanel.SetMargin(0, 10, 0, 0);


            _pausedPanel.Children.Add(_pausedText);


            ///////////////////////////////////////////////////////////////////////////////////////
            //  panel Setup
            //

            summaryPanel.Children.Add(_topPanel);
            summaryPanel.Children.Add(_midPanel);
            summaryPanel.Children.Add(_bottomPanel);
            summaryPanel.Children.Add(_pausedPanel);

            Child = summaryPanel;

        }



      
        //--//
        //--//

        #region gesture handlers

        public void PauseRide()
        {
            _pausedPanel.Visibility = Visibility.Visible;
            this.Invalidate();
        }

        public void ResumeRide()
        {
            _pausedPanel.Visibility = Visibility.Hidden;
            this.Invalidate();
        }

        #endregion


        //--//
        StackPanel _pausedPanel;
    }
}

